package com.yyx.app1.Question_function.Control.petinfo;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.yyx.app1.Data.Question.MedicalHistoryData;
import com.yyx.app1.Data.testDate;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by yuexing on 2015/10/22.
 */
public class PetInfoListViewAdapter extends BaseAdapter {
    private Context context;
    private final int BaseInfo = 0;
    private final int Head = 1;
    private final int Immunization = 2;
    private final int MedicalHistory = 3;
    private int typecount = 4;
    private List<HashMap<String,String>> immunizationList;
    private List<HashMap<String,MedicalHistoryData>> MedicalHistoryList;

    public PetInfoListViewAdapter(Context context) {
        this.context = context;
    }

    public void findAll()
    {
        immunizationList =new ArrayList<>();
        MedicalHistoryList = new ArrayList<>();
        for (int i = 0 ; i<4 ; ++i)
        {
            HashMap<String,String> map = new HashMap<>();
            map.put("time","2015/10/25");
            map.put("jilu", "犬疫苗");
            immunizationList.add(map);
            HashMap<String,MedicalHistoryData> hashMap = new HashMap<>();
            hashMap.put("1",null);
            MedicalHistoryList.add(hashMap);
        }
    }

    @Override
    public int getViewTypeCount() {
        return typecount;
    }

    @Override
    public int getItemViewType(int position) {
        if (position==0)
            return BaseInfo;
        else if (position==1)
            return Head;
        else if (position>1 && position<immunizationList.size()+2)
            return Immunization;
        else if (position == immunizationList.size()+2)
            return Head;
        else
        {
            return MedicalHistory;
        }
    }

    @Override
    public int getCount() {
        return immunizationList.size()+MedicalHistoryList.size()+3;
    }

    @Override
    public Object getItem(int position) {
        if (position==0)
            return null;
        else if (position==1)
            return null;
        else if (position>1 && position<immunizationList.size()+2)
            return immunizationList.get(position-2);
        else if (position == immunizationList.size()+2)
            return null;
        else
        {
            return MedicalHistoryList.get(position-immunizationList.size()-3);
        }
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        try
        {
            Item_PetBaseInfo base;
            Item_PetInfo_immunization immunization;
            Item_PetInfo_MedicalHistory medicalHistory;
            Item_PetInfo_ListHead head;
            if (convertView==null)
            {
                if (position==0)
                {
                    base = Item_PetBaseInfo_.build(context);
                    base.bind();
                    return base;
                }
                else if (position==1)
                {
                    head = Item_PetInfo_ListHead_.build(context);
                    head.bind("免疫记录");
                    return head;
                }
                else if (position>1 && position<immunizationList.size()+2)
                {
                    immunization = Item_PetInfo_immunization_.build(context);
                    immunization.bind(position,"2015/11/22","三联疫苗");
                    return immunization;
                }
                else if (position == immunizationList.size()+2)
                {
                    head = Item_PetInfo_ListHead_.build(context);
                    head.bind("诊疗记录");
                    return head;
                }
                else
                {
                    medicalHistory = Item_PetInfo_MedicalHistory_.build(context);
                    medicalHistory.bind("狂犬病","第一宠物医院","注射疫苗","2015/10/24",position);
                    return medicalHistory;
                }
            }
            else
            {
                if (position==0)
                {
                    base = (Item_PetBaseInfo)convertView;
                    base.bind();
                    return base;
                }
                else if (position==1)
                {
                    head = (Item_PetInfo_ListHead)convertView;
                    head.bind("免疫记录");
                    return head;
                }
                else if (position>1 && position<immunizationList.size()+2)
                {
                    immunization = (Item_PetInfo_immunization)convertView;
                    immunization.bind(position, "2015/11/22","三联疫苗");
                    return immunization;
                }
                else if (position == immunizationList.size()+2)
                {
                    head = (Item_PetInfo_ListHead)convertView;
                    head.bind("诊疗记录");
                    return head;
                }
                else
                {
                    medicalHistory = (Item_PetInfo_MedicalHistory)convertView;
                    medicalHistory.bind("狂犬病","第一宠物医院","注射疫苗","2015/10/24",position);
                    return medicalHistory;
                }
            }
        }
        catch (Exception e)
        {
            Log.e("异常1510221156",e.toString());
            return null;
        }
    }
}
